package com.example.flink.wordcount;

import org.apache.commons.lang3.StringUtils;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.util.Collector;

public final class wordCount implements FlatMapFunction<String, Tuple2<String, Integer>>{

    @Override
    public void flatMap(String s, Collector<Tuple2<String, Integer>> out) throws Exception {
        String[] tokens = s.toLowerCase().split("\\W+");
        for (String token : tokens){
           if (StringUtils.isNotBlank(token)){
               out.collect(new Tuple2<>(token, 1));
           }
        }
    }
}
